<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var arr = [1, 3, 5, 7, 9, 4, 2, 6, 8, 0]

        function myEach(list, fn) {
            for (i = 0; i < list.length; i++) {
                var item = list[i]
                var index = i
                var array = list
                fn(item, index, array)
            }
        }
        myEach(arr, function (item, index, array) {
            console.log(item, index, array)
        })

        /*----------------------------------------*/
        function myMap(list, fn) {
            var newArr = []
            for (i = 0; i < list.length; i++) {
                var item = list[i]
                var index = i
                var array = list
                newArr.push(fn(item, index, array))
            }
            return newArr
        }
        var res = myMap(arr, function (item, index, array) {
            return item - 20
        })

    </script>
</body>

</html>